home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_136 / iff2pcs / source / pzblit.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  68 lines

  1. #include "pz.h"
  2.  
  3. /* Various bitmap/blitter routines for IFF2PCS
  4. ** Ali Ozer, Nov 1987
  5. ** Fixed memory lossage problem with half-allocated bitmaps Dec '87
  6. */
  7.  
  8. /* InitBM will try to allocate d (depth) bitplanes of w x h bits each. It'll 
  9. ** actually round w upto a multiple of 8 bits. If unsuccessful, InitBM will
  10. ** return false and set bm->Depth to the actual number of bit planes allocated.
  11. ** If successful, bm->Depth will be set to d and InitBM will return true.
  12. ** To deallocate the bitmap correctly, simply call FreeBM.
  13. */
  14. int InitBM (bm, h, w, d)
  15. struct BitMap *bm;
  16. int h, w, d; /* Height, width, depth, in bits, bits, and bitplanes */
  17. {
  18.   int cnt;
  19.  
  20.   w = ((w+7) >> 3) << 3;  /* We allocate upto 7 extra bits... */
  21.  
  22.   bm->BytesPerRow = w >> 3;   /* In bytes */
  23.   bm->Rows        = h;
  24.   bm->Depth       = d;
  25.  
  26.   for (cnt = 0; cnt < d; cnt++) 
  27.     if ((bm->Planes[cnt] = (PLANEPTR) AllocRaster((long)w, (long)h)) == NULL) {
  28.       bm->Depth = cnt; 
  29.       return (false);
  30.     }
  31.  
  32.   return (true);
  33. }
  34.  
  35.  
  36. void FreeBM (bm)
  37. struct BitMap *bm;
  38. {
  39.   int cnt;
  40.   long w = (bm->BytesPerRow) << 3;
  41.   long h = (bm->Rows);
  42.  
  43.   for (cnt = 0; cnt < bm->Depth; cnt++)
  44.     if (bm->Planes[cnt] != NULL) FreeRaster (bm->Planes[cnt], w, h);
  45. }
  46.   
  47.  
  48. CopyFromBMToBM (srcbm, srcx, srcy, destbm, destx, desty, sizex, sizey)
  49. struct BitMap *srcbm, *destbm;
  50. int srcx, srcy, destx, desty, sizex, sizey;
  51. {
  52.   /* The "c0" indicates copy; the "ff" indicates include all planes */
  53.   BltBitMap (srcbm,  (long)srcx, (long)srcy, 
  54.              destbm, (long)destx, (long)desty,
  55.              (long)sizex, (long)sizey, 0x00c0L, 0x00ffL, NULL);  
  56. }
  57.  
  58.  
  59. XORFromBMToBM (srcbm, srcx, srcy, destbm, destx, desty, sizex, sizey)
  60. struct BitMap *srcbm, *destbm;
  61. int srcx, srcy, destx, desty, sizex, sizey;
  62. {
  63.   BltBitMap (srcbm,  (long)srcx, (long)srcy, 
  64.              destbm, (long)destx, (long)desty,
  65.              (long)sizex, (long)sizey, 0x0060L, 0x00ffL, NULL);  
  66. }
  67.  
  68.